  <template>
    <div id="indexContainer">
    <swiper  :indicator-dots="true" indicator-color="rgba(0, 0, 0, 0.4)" 	indicator-active-color="white" @click="toDetailUrl">
      <swiper-item>
        <img :src=articles[swiperUrl[0]].imageSrc alt="" @click="toDetailUrl(swiperUrl[0])">
      </swiper-item>
      <swiper-item>
        <img :src=articles[swiperUrl[1]].imageSrc alt="" @click="toDetailUrl(swiperUrl[1])">
      </swiper-item>
      <swiper-item>
        <img :src=articles[swiperUrl[2]].imageSrc alt="" @click="toDetailUrl(swiperUrl[2])">
      </swiper-item>
    </swiper>

      <div class="width1200 clearfix">
        <!-- 标题栏 -->
        <div class="title_taday">
          <div class="class_title">
            <dl>
              <dt><strong>今日</strong>推荐</dt>
              <dd>TODAY RECOMMEND</dd>
            </dl>
            <p></p>
            <ol>
              <li>
                <p class="month"><span>{{ date.month }}</span>月</p>
                <p class="day">{{ date.day }}</p>
              </li>
            </ol>

          </div>
        </div>
        </div>
      <!-- 精选文章 -->
      <view id="hotArticleView">
        <!-- 文章总标题 -->
        <view id="hotArticleTitleView" >精选文章</view>
        <!-- 文章列表    Ctrl+C Ctrl+V：复制粘贴，如果没有选中任何文字则复制粘贴一行-->
        <view class="articleView" v-for="(article, index) in articles" :key="index">
          <image :src=article.imageSrc></image>
          <view class="articleContent">
            <view class="artivcleTitle">{{ article.title }}</view>
            <view class="articleDesc">{{article.description}}</view>
            <view id="moreView1" @click="toDetailUrl(index)">查看详情</view>
          </view>
        </view>
        <!-- 查看更多 -->
        <view id="moreView">
          <view class="arrow" @click="getMore">{{msgInfo}}</view>
        </view>
      </view>

    </div>
  </template>

  <script>
import config from "../../config"
export default {
  data(){
    return{
      swiperFlag:'true',
      swiperUrl: [],
      msgInfo:'查看更多',
      date:{
        month:'',
        day:''
      },

      articles: [
        {
          content:'',
          healthInfoId:'1',
          createData:'',
          title: '你活出自我的样子，真美',
          description: '千百年来，古人总把人的品格与自然之物相联系起来，以花草树木之品性喻人的精神情操。',
        }
        ]
    }
  },
     onReady(){
      this.getCurrentTime()
      this.getMore()

  },
  methods:{
    init(){
      console.log(this.articles.length)
      while (this.swiperUrl.length < 3) {
        const randomNumber = Math.floor(Math.random()*this.articles.length)
        if (!this.swiperUrl.includes(randomNumber)) {
          this.swiperUrl.push(randomNumber);
        }
      }
    },
      toDetailUrl(index) {
      console.log(this.articles[index])
        //获取资讯详情
        wx.navigateTo({
          url:'/pages/healthMessage/main?data='+JSON.stringify(this.articles[index]),
          }
        )
      },
      getCurrentTime() {
        const now =new Date();
        this.date.month=now.getMonth()+1;
        this.date.day=now.getDate();
      },
      async getMore(){
        var arr=[];
        if(this.articles.length===0) arr=[];
         else {
           for(let i=0; i<this.articles.length; i++)
           {
             arr.push(this.articles[i].healthInfoId);
           }
        }
        const healthUrl=config.healthUrl;
        await wx.request({
           method:"POST",
           url:healthUrl,
          data:{
            ids:arr
          },
          success:(res)=>{this.articles=[]
             if(res.data.msg==="暂无更多") this.msgInfo=res.data.msg
                for(let i=0; i<res.data.data.length; i++)
                {
                  this.articles.push(res.data.data[i])
                }
             if(this.swiperFlag){
               this.init()
               this.swiperFlag=false
             }

          }
        })
      }
  }
}
  </script>

  <style lang="stylus" rel="stylesheet/stylus">
  #indexContainer
    position absolute
    width 100%
    height 30%
    margin 0px -5px 0px -5px
    swiper
      width 100%
      height 100%
      img
        width 100%
        height 100%
  /* 精选文章 */
  #hotArticleView{
    padding: 0 30px;
    background: #FFFFFF;
    margin-bottom: 24px;
  }
  #hotArticleTitleView{
    height: 88px;
    font-size: 15px;
    font-weight: bold;
    border-bottom: 1rpx solid #F1EEF5;
    line-height: 88px;
  }
  .articleView{
    display: flex;
    padding: 30px 0;
    border-bottom: 1px solid #F1EEF5;
  }
  .articleView image{
    height: 120px;
    width 120px
    margin-right: 20px;
  }
  .articleTitle{
    font-size: 28px;
    font-weight: bold;
    line-height: 50px;
  }
  .articleContent{
    position:relative
    width: 70%
  }
  .articleDesc{
    color: #B7B7B7;
    line-height: 25px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
      }
  #moreView{
    height: 44px;
    line-height: 44px;
    font-size: 10px;
    color: #a39f9f;
    position: relative;
  }


  #moreView1{
    height: 22px;
    line-height: 22px;
    font-size: 10px;
    position: absolute;
    left: 70%;
    top: 100%;
    width: 50px;
    color: #7692e2;
  }

  .title_taday {
    padding-bottom: 14px;
  }
  .class_title {
    position: relative;
    width: 100%;
    height: 70px;
  }
  .title_taday .class_title dl {
    position: relative;
    top:6.5px;
    float: right;
    left: -72.5px;
    background-color: rgba(#f1f3f7);
  }
  .title_taday .class_title dl dt {
    background-position: -313px 10px;
    display: inline-flex;
    position: relative;
    float: right;
    font-size: 40px;
  }
  .title_taday .class_title dl dt strong {
    font-weight: bold;
  }
  .title_taday .class_title dl dd {
    padding-top: 7px;
    font-size:12px;
    left: 14px;
    position: relative;
  }
  .class_title>p {
    height: 45px;
    border-bottom: 2px solid #d4d4d4;
  }
  .title_taday .class_title ol {
    position: absolute;
    top: 10px;
    left: 20%;
    width: 64px;
    height: 63px;
    background-color: #fff;
    z-index: 10;
  }
  .title_taday .class_title ol li {
    height: 62px;
    box-shadow: 0px 2px 5px rgba(17,6,11,.15);
    text-align: center;
  }
  .title_taday .class_title ol li .month {
    height: 20px;
    background: #ef5a52;
    line-height: 20px;
    font-size: 14px;
    color: #fff;
  }
  .title_taday .class_title ol li .month span {
    font-size: 13px;
  }
  .title_taday .class_title ol li .day {
    font-size: 24px;
    color: #4b4b4b;
    font-weight: bold;
    line-height: 36px;
  }
  </style>
